import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Iterator;

import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;


public class Practice2 {

	/**
	 * @param args
	 */
	
	private static HSSFSheet mySheet = null;
	private static HSSFWorkbook myBook = null;
	
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		
		System.out.println("Software Started !!");
		
		//read();
		write();
	}

	private static void write()
	{
		myBook = new HSSFWorkbook();
		mySheet = myBook.createSheet("Java Excels");
		HSSFRow myRow = mySheet.createRow(mySheet.getLastRowNum() + 1);
		HSSFCell myCell = myRow.createCell(0);
		myCell.setCellValue("My Cell Value2");
		
		FileOutputStream fOut = null;
		try {
			fOut = new FileOutputStream("./testExcel.xls");
			
			myBook.write(fOut);
			fOut.flush();
			fOut.close();
		} catch (Exception e) 
		{
			e.printStackTrace();
		}

		System.out.println(myBook.getNumberOfSheets());
	}
	
	private static void read()
	{
		FileInputStream fis = null;
		
		try {
			fis = new FileInputStream("./testExcel.xls");
			
			myBook = new HSSFWorkbook(fis);
			mySheet = myBook.getSheetAt(0);
			
			System.out.println("Workbook read");
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} finally {
			if(fis != null)
				try {
					fis.close();
				} catch (IOException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
		}
	}
}
